package com.cyy.api.controller;

import com.cyy.common.annotation.OperationLog;
import com.cyy.common.domain.Response;
import com.cyy.common.pojo.req.PageArticleReq;
import com.cyy.common.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author caoyunyou
 */
@Tag(name = "文章-API", description = "文章-API")
@RestController
@RequestMapping("/v1/article")
@RequiredArgsConstructor
public class ApiArticleController {

    private final ArticleService articleService;

    @OperationLog("分页查询文章展示信息")
    @PostMapping("/page")
    public Response queryPage(@RequestBody PageArticleReq req) {
        return Response.success().data(articleService.queryPage(req));
    }

    @OperationLog("查询文章详细信息:查看文章")
    @GetMapping("/details/{id}")
    public Response details(@PathVariable(value = "id") Long id) {
        return Response.success().data(articleService.queryDetailsById(id));
    }

    @Operation(description = "文章查询")
    @GetMapping("/search")
    public Response search(@RequestParam(name = "keywords") String keywords) {
        return Response.success().data(articleService.searchArticleByKeyWords(keywords));
    }

    @Operation(summary = "分页展示归档")
    @GetMapping("/archive")
    public Response archive() {
        return Response.success().data(articleService.pageArchive());
    }
}
